<?php
class Wanfa extends  Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('article_model');
        $this->load->model('track_model');
        $this->load->model('comment_model');
        $this->load->model('category_model');

    }


    public function getlist()
    {
        $data = $_GET;
        $lines = $this->article_model->track_act_search($data);
        
		$this->success($lines);
    }

    public function detail()
    {
    	if(!empty($_GET['id']))
    	{$id = $_GET['id'];}
    	else{
    		$this->error('id is null');
    	}
    	switch(strtoupper($_GET['type'])){
    		case 'TRACK':
    			$data = $this->track_model->detail($id);            
                if(empty($data))
                {$this->error('线路不存在');}
                $con_data['type'] = 'TRACK';
    			break;
    		case 'ACTIVITY':
    			$data = $this->article_model->detail($id);
    			if(empty($data))
                {$this->error('线路不存在');}
                $con_data['type'] = 'ACTIVITY';
    			break;
    		default:
    			$this->error('玩法类型错误');
    	}

        $con_data['id'] = $id;
        $con_data['limit'] = 5;
        $con_data['offset'] = 0;
        $coms = $this->comment_model->getActivityOrTrackComments($con_data);

        $this->success(array('data'=>$data,'coms' =>$coms));

    }
    
    public function getImagewall()
    {
    	if(!empty($_GET['id']))
    	{$id = $_GET['id'];}
    	else{
    		$this->error('id is null');
    	}
    	switch(strtoupper($_GET['type'])){
    		case 'TRACK':
    			$data = $this->track_model->getimagewall($id);
    			break;
    		case 'ACTIVITY':
    			$data = $this->article_model->getimagewall($id);
    			break;
    		default:
    			$this->error('玩法类型错误');
    	}
    	$this->success($data);   	
    }
    
    public function getComments()
    {
    	//玩法id
        if(empty($_GET['id']))
    	{$this->error('id is null');}
    	$id = $_GET['id'];
    	//分页参数
    	if(empty($_GET['page']))
    	$page = 1;
    	else 
    	$page = $_GET['page'];
    	
    	$limit=$page*5;
    	$offset=0;
    	//玩法类型
        if($_GET['type'] == 'TRACK')
        {
            $con_data['type'] = 'TRACK';
        }elseif($_GET['type'] == 'ACTIVITY')
        {
            $con_data['type'] = 'ACTIVITY';
        }else{
            $this->error('玩法类型错误');
        }
        //获取评论
    	$con_data['id'] = $id;
    	$con_data['limit'] = $limit;       
    	$con_data['offset'] = $offset;
    	$coms = $this->comment_model->getActivityOrTrackComments($con_data);
    	$this->success($coms);
    }


    public function gettype()
    {
       //获取玩法(id=3)的分类
       $data =  $this->category_model->all_categories(array('parentId'=>3));
        $this->success($data);
    }
    
    public function getmap()
    {
    	if(is_numeric($_GET['id']) && $_GET['id']>0){
    		$id=$_GET['id'];
    	}else{
    		$id=0;
    	}    		
    	$data = $this->track_model->gettodolist($id);
    	$this->success($data);
    }




}
